package unit.integrator;

import java.util.Random;

import unit.panels.AbstractPanel;
import main.ResourceManager;

import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.SpriteGroup;

public class WalkerGenerator {
	private ResourceManager generatorResource = new ResourceManager("GeneratorResource.properties");

	SpriteGroup spriteWalkers,spritePanels;
	Background b;
	private int BOARD_WIDTH;
	private int BOARD_HEIGHT;
	
	
	public WalkerGenerator(int x, int y){
		BOARD_WIDTH = x;
		BOARD_HEIGHT = y;
		b = new Background(BOARD_WIDTH,BOARD_HEIGHT);
		}
	public WalkerGenerator(){
		
	}
	
	public Sprite randomlyGenerateWalker(){
		String[] walkers = generatorResource.getStringArray("Walkers");
		Random rand = new Random();
		return getInstance(walkers[rand.nextInt(walkers.length)]);	
		
	}

	public SpriteGroup randomlyGenerateAllPanels(){
		String[] panels = generatorResource.getStringArray("Panels");
		Random random = new Random();
		int panelCount = generatorResource.getInteger("NumberofPanels");
		for(int i = 0; i < panelCount; i++){
			AbstractPanel panelp = getPanelInstance(panels[random.nextInt(panels.length)]);
			panelp.setLocation(random.nextInt(BOARD_WIDTH), random.nextInt(BOARD_HEIGHT));
		spritePanels.add(panelp);	
	}
		return spritePanels;
}
	







/*
 * returns a new unspecified SpriteWalker Object
 */
	@SuppressWarnings("unchecked")
	private AbstractPanel getInstance(String walkerType) {
		Class<AbstractPanel> myClass = null;
		try {
			myClass = (Class<AbstractPanel>) Class.forName(walkerType);
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		AbstractPanel walker = null;
		try {
			walker = myClass.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return walker;
	}
	
	/*
	 * returns a new unspecified SpriteWalker Object
	 */
		@SuppressWarnings("unchecked")
		private AbstractPanel getPanelInstance(String panelType) {
			Class<AbstractPanel> myClass = null;
			try {
				myClass = (Class<AbstractPanel>) Class.forName(panelType);
			} catch (ClassNotFoundException e1) {
				e1.printStackTrace();
			}
			AbstractPanel panel = null;
			try {
				panel = myClass.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			return panel;
		}
}